package com.edu.exam.enums.status.grade;

import com.edu.exam.enums.core.StatusEnum;

/**
 * 成绩状态枚举
 */
public enum GradeStatus implements StatusEnum {
    DRAFT("DRAFT", "草稿"),
    PENDING_REVIEW("PENDING_REVIEW", "待审核"),
    APPROVED("APPROVED", "已审核"),
    PUBLISHED("PUBLISHED", "已发布"),
    ARCHIVED("ARCHIVED", "已归档");

    private final String code;
    private final String description;

    GradeStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }
    
    @Override
    public String getCode() {
        return code;
    }
    
    @Override
    public String getDescription() {
        return description;
    }
    
    public boolean isActive() {
        return APPROVED.equals(this) || PUBLISHED.equals(this);
    }
    
    public boolean isEditable() {
        return DRAFT.equals(this) || PENDING_REVIEW.equals(this);
    }
    
    public boolean isCompleted() {
        return PUBLISHED.equals(this) || ARCHIVED.equals(this);
    }
    
    public static GradeStatus fromCode(String code) {
        if (code == null) {
            return null;
        }
        for (GradeStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}
